package com.lagou.homework;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/*
 * @className NumSortDriver
 * @description 驱动类
 * @author admin
 * @date 2022/5/15 23:00
 * */
public class NumSortDriver {

    public static void main(String[] args) {
        // 1.获取hadoop配置文件conf对象并通过该对象获取job实例对象
        Configuration conf = new Configuration();
        try {
            Job job = Job.getInstance(conf,"NumSortDriver");
            // 2.指定程序jar的本地路径
            job.setJarByClass(NumSortDriver.class);
            // 3.指定mapper/reducer类
            job.setMapperClass(NumSortMapper.class);
            job.setReducerClass(NumSortReducer.class);
            // 4.指定mapper类的kv输出类型
            job.setMapOutputKeyClass(IntWritable.class);
            job.setMapOutputValueClass(IntWritable.class);
            // 5.指定最终输出的kv类型
            job.setOutputKeyClass(IntWritable.class);
            job.setOutputValueClass(IntWritable.class);
            // 6.指定job处理的数据的输入路径
            FileInputFormat.setInputPaths(job, new Path(args[0]));
            // 7.指定job输出数据的路径
            FileOutputFormat.setOutputPath(job, new Path(args[1]));
            // 8.提交作业
            boolean flag = job.waitForCompletion(true);
            System.exit(flag?0:1);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
